<template>
    <div class="Count">
        <h2>当前求和为{{ sum }}</h2>
        <h2>当前姓名为{{ name }}</h2>
        <h2>当前年龄为{{ age }}</h2>

        <select v-model="n">
            <option :value="1">1</option>
            <option :value="2">2</option>
            <option :value="3">3</option>
        </select>
        <button @click="add">加</button>
        <button @click="minus">减</button>

    </div>
</template>


<script setup lang="ts" name="Conut">
    import {ref,toRefs} from 'vue'
    import { useCountStore } from '@/store/count'
    import { storeToRefs } from 'pinia'

    const CountStore =useCountStore()
    //storeToRefs只作用于store中的数据，不会对方法进行ref包裹
    const {sum,name,age} =storeToRefs(CountStore)

    //数据
    let n = ref(1)//用户选择的数字

    //方法
    //方式一
    function add(){
        // CountStore.sum+=1
    //方式二
    // CountStore.$patch({
    //     sum:889,
    //     name:'蚩梦',
    //     age:20
    // })
    // 方式三
    CountStore.increment(n.value)
    }
    



    function minus(){
        CountStore.sum-=n.value
    }
</script>



<style >
    .Count {
        background-color: aqua;
        box-shadow: 0 0 10px;
        border-radius: 10px;
        padding: 20px;
    }
    button {
        margin: 0 5px;
    }
</style>